/*
 This file is part of BTStracker
		
    BTStracker is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    BTStracker is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Foobar.  If not, see <http://www.gnu.org/licenses/>.	
	author: azbest.pro (azbest.pro@gmail.com)
*/
package pl.vdl.azbest.mremote;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.InvalidPropertiesFormatException;
import java.util.List;
import java.util.logging.Logger;

import gnu.io.CommPortIdentifier;

import pl.vdl.azbest.annotations.InProgress;
import pl.vdl.azbest.annotations.Level;
import pl.vdl.azbest.annotations.TODO;
import pl.vdl.azbest.annotations.Team;
import pl.vdl.azbest.log.LoggingTheGathering;

@InProgress
@TODO(level = Level.CRITICAL, target = "<br>" +
		  "1. query devices <br>"
		+ "2. gui init<br>" + "3. xml config load when available<br>"
		+ "4. Conf init<br>", done = "", responsible = Team.AZBEST)
/**
 * Starting application
 */
public class MCStart {
	public static void main(String[] args) {
		confBasicInit();
		queryDevices();
		initilizeGUI();
	}
	{
		LoggingTheGathering.addPath(getClass().getName());
	}

	private static  void confBasicInit() {
		//Conf.getInstance().setLoggingRoot("pl.vdl.azbest.comm.mc");
	//	Conf.getInstance().loadConfigurationData();
		Logger.getLogger("pl.vdl.azbest.mremote.com").setLevel(java.util.logging.Level.ALL);
		Conf.getInstance().setGPRSCellQueringCount(100);
   

		try {
			Conf.loadLanguage("mremote_lang.xml");
		} catch (InvalidPropertiesFormatException  e) {
			e.printStackTrace();
		}
		catch (FileNotFoundException e) {
			e.printStackTrace();
		}catch (IOException e) {
			e.printStackTrace();
		}

		//InvalidPropertiesFormatException, FileNotFoundException, IOException

	}

	private static void initilizeGUI() {
		COMCommander gui = new COMCommander();
		gui.openSWTWidgetStandAlone2();
	}

	private static void queryDevices() {
		// get comm ports
		List<CommPortIdentifier> portList = new ArrayList<CommPortIdentifier>();
		Enumeration ports = CommPortIdentifier.getPortIdentifiers();
		while (ports.hasMoreElements()) {
			CommPortIdentifier port = (CommPortIdentifier) ports.nextElement();
			if (port.getPortType() == CommPortIdentifier.PORT_SERIAL)
				portList.add(port);
		}

		// set current port
		Conf.getInstance().setAvailableCommPorts(portList);
		Conf.getInstance().setDevicePort(portList.get(0));

	}
	public static void  testMain(){
		confBasicInit();
		queryDevices();
		//initilizeGUI();
	}


}
